//
//  FeedbackViewModel.swift
//  Exchange
//
//  Created by rui on 2018/7/6.
//  Copyright © 2018年 common. All rights reserved.
//

import UIKit

class FeedbackViewModel: BaseViewModel {
    
    var content: String = ""
    
    private lazy var feedbackApi: FeedbackRequest = {
        let api = FeedbackRequest()
        api.dataReformer = self
        api.paramSource = self
        api.delegate = self
        return api
    }()
    
    func uploadFeedback(content: String) {
        self.content = content
        self.feedbackApi.loadData()
    }
}

extension FeedbackViewModel: RequestCallBack,RequestDataReformer,RequestParamSource {
    
    func reform(_ request: BaseRequest, _ data: [String : Any]?) {
        if let _ = request as? FeedbackRequest {
            self.response?(ResponseState.mine_feedback,true, nil)
        }
    }
    
    func requestDidSucess(_ request: BaseRequest) {
        
    }
    
    func requestDidFail(_ request: BaseRequest) {
        if let _ = request as? FeedbackRequest {
            self.response?(ResponseState.mine_feedback,false, request.errorMsg)
        }
    }
    
    func requestParams(_ request: BaseRequest) -> [String : Any]? {
        var pramas: [String:Any] = [:]
        if let _ = request as? FeedbackRequest {
            pramas.updateValue(self.content, forKey: "content")
        }
        return pramas
    }
    
}
